export default {
  methods: {
    // 关闭当前窗口
    closeCurrentTab(cb) {
      // if(!isNaN(endStr)){
      //   reg = new RegExp('/product-course/' + route.params.category)
      // } else {
      //   reg = new RegExp('/product-course/' + route.params.category + '.*/' + endStr)
      // }
      var tabName = this.$store.state.contentTabsActiveName
      this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.cname !== tabName)
      if (this.$store.state.contentTabs.length <= 0) {
        this.$store.state.sidebarMenuActiveName = this.$store.state.contentTabsActiveName = 'home'
        return false
      }
      if (tabName === this.$store.state.contentTabsActiveName) {
        let temp = tabName.split('/');
        let reg = new RegExp('/product-course/' + temp[2] + '/.*/' + 'lesson-normal/' + temp[temp.length - 1])     //匹配普通课程详情-新建编辑课时
        let regNormalLesson = new RegExp('/product-course/' + temp[2] + '/.*/' + 'lesson-normal')     //匹配普通课程详情页路径
        // let regPackageLesson = new RegExp('/product-course/' + temp[2] + '/.*/' + 'lesson-normal')     //匹配套餐课复制课程详情页路径
        let toTab;
        if (!temp[2]) {
          // 系列课和套餐课
          let seriesOrPackage = tabName.split('-')[3]
          toTab = this.$store.state.contentTabs.filter(item => item.cname === 'product-course-' + seriesOrPackage)
        } else if (reg.test(tabName)) {
          // 普通课程详情-新建编辑课时  
          toTab = this.$store.state.contentTabs.filter(item => regNormalLesson.test(item.cname))
        } else {
          toTab = this.$store.state.contentTabs.filter(item => item.params.category === temp[2] || tabName.includes(item.cname))
        }
        if (cb) {
          cb()
        } else {
          this.$router.push(toTab.length > 0 ? toTab[toTab.length - 1] : { name: 'home' })
        }
      }
    }
  }
}
